import { list as getList } from '../../api/index'
Component({
	properties: {
		list: {
			type: Array,
			value: []
		},
		isShow: {
			type: Boolean,
			value: false
		},
		leavl: {
			type: Number,
			value: 3
		}
	},
	/**
	 * 页面的初始数据
	 */
	data: {
		current: '',
		current2: '',
		navHeight: getApp<IAppOption>().globalData.navHeight + getApp<IAppOption>().globalData.statusHeight,
		list: getApp<IAppOption>().globalData.MenuTree
	},
	ready() {
		this.setData({
		})
	},
	methods: {
		click1(e) {
			const index = e.currentTarget.dataset.index
			this.setData({
				current: this.data.current !== index ? index : '',
				current2: ''
			})
		},
		click2(e) {
			const index = e.currentTarget.dataset.index
			this.setData({
				current2: this.data.current2 !== index ? index : ''
			})
			wx.showLoading({ title: '',mask: true})
			getList({
				pageIndex: 1,
				pageSize: 10,
				directoryId: e.currentTarget.dataset.item.id
			}).then(res => {
				const { current, current2, list } = this.data
				list[current].childList[current2].childList = res.data.rows
				this.setData({ list })
				wx.hideLoading()
			}).catch(err => {
				wx.hideLoading()
			})
		},
		click3(e) {
			var myEventDetail = e.currentTarget.dataset.item// detail对象，提供给事件监听函数
      var myEventOption = {} // 触发事件的选项
			this.triggerEvent('directoryClick', myEventDetail, myEventOption)
		},
		isShow() {
			this.setData({
				isShow: !this.data.isShow
			})
		},
		searchClick() {
			var myEventDetail = {} // detail对象，提供给事件监听函数
      var myEventOption = {} // 触发事件的选项
			this.triggerEvent('searchClick', myEventDetail, myEventOption)
		}
	}
})